package com.csnf.dao;

import com.csnf.entity.Admin;
import com.csnf.util.JdbcUtil;

import java.sql.*;

/**
 * 对admin表的增删改查操作
 */
public class AdminDao {
    /**
     * 查询用户通过账号密码
     */
    public Admin getAdminByNamePwd(Admin admin) throws SQLException {
        String sql ="select * from admin where admin_name=? and admin_password=?";
        Connection conn = JdbcUtil.getConnection();
        PreparedStatement ps = JdbcUtil.getPreparedStatement(conn, sql, admin.getAdmin_name(), admin.getAdmin_password());
        ResultSet rs = ps.executeQuery();
        if (rs.next()){
            try {
                admin = JdbcUtil.invokeObject(rs, Admin.class);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            JdbcUtil.close(rs,ps,conn);  //释放资源
            return admin;
        }
        JdbcUtil.close(rs,ps,conn);  //释放资源
        return null;
    }
}
